package com.meituan.catering.management.shop.biz.model.converter;

import com.meituan.catering.management.shop.api.http.model.response.ShopDetailHttpResponse;
import com.meituan.catering.management.shop.api.http.model.response.ShopPageHttpResponse;
import com.meituan.catering.management.shop.biz.model.ShopBO;
import com.meituan.catering.management.shop.biz.model.common.PageBO;
import com.meituan.catering.management.shop.biz.model.enumeration.DescribableEnum;

import static java.util.stream.Collectors.toList;

/**
 * @Author:ale
 * @Date 2022/4/22 17:06
 * @Version 1.0
 */
public abstract class ShopVOConverter {


    public static ShopDetailHttpResponse fromBO(ShopBO shopBO) {
        ShopDetailHttpResponse httpResponse = new ShopDetailHttpResponse();
        httpResponse.setBusinessNo(shopBO.getBusinessNo());
        httpResponse.setName(shopBO.getName());
        httpResponse.setBusinessType(shopBO.getBusinessType().getName());
        httpResponse.setManagementType(shopBO.getManagementType().getName());
        httpResponse.getContact().setContactTelephone(shopBO.getContact().getContactTelephone());
        httpResponse.getContact().setContactCellphone(shopBO.getContact().getContactCellphone());
        httpResponse.getContact().setContactAddress(shopBO.getContact().getContactAddress());
        httpResponse.getContact().setContactName(shopBO.getContact().getContactName());
        httpResponse.getOpeningHours().setOpeningHoursStart(shopBO.getOpeningHours().getOpeningHoursStart());
        httpResponse.getOpeningHours().setOpeningHoursEnd(shopBO.getOpeningHours().getOpeningHoursEnd());
        httpResponse.setBusinessArea(shopBO.getBusinessArea());
        httpResponse.setComment(shopBO.getComment());
        httpResponse.setEnabled(shopBO.getEnabled().getBooleanValue());
        return httpResponse;
    }

    public static ShopPageHttpResponse fromPageBO(PageBO<ShopBO> shopPageBO){
        if (shopPageBO == null){
            return null;
        }
        ShopPageHttpResponse httpResponse = new ShopPageHttpResponse();
        httpResponse.setPageIndex(shopPageBO.getPageIndex());
        httpResponse.setPageSize(shopPageBO.getPageSize());
        httpResponse.setTotalCount(shopPageBO.getTotalCount());
        httpResponse.setTotalPageCount(shopPageBO.getTotalPageCount());
        httpResponse.getRecords().addAll(
                shopPageBO.getRecords().stream()
                .map(ShopVOConverter::fromPageBORecord)
                .collect(toList()));
        return httpResponse;
    }

    public static ShopPageHttpResponse.Record fromPageBORecord(ShopBO shopBO){
        if (shopBO == null){
            return null;
        }
        ShopPageHttpResponse.Record record = new ShopPageHttpResponse.Record();

        record.setId(shopBO.getId());
        record.setTenantId(shopBO.getTenantId());

        record.setSuperiorId(shopBO.getSuperiorId());
        record.setBusinessNo(shopBO.getBusinessNo());
        record.setName(shopBO.getName());
        record.setBusinessType(shopBO.getBusinessType().getName());
        record.setManagementType(shopBO.getManagementType().getName());
//        record.getBusinessType().setBusinessType(shopBO.getBusinessType().getName());
//        record.getManagementType().setManagementType(shopBO.getManagementType().getName());
        record.getContact().setContactName(shopBO.getContact().getContactName());
        record.getContact().setContactCellphone(shopBO.getContact().getContactCellphone());
        record.getContact().setContactTelephone(shopBO.getContact().getContactTelephone());
        record.getContact().setContactAddress(shopBO.getContact().getContactAddress());
        record.getOpeningHours().setOpeningHoursStart(shopBO.getOpeningHours().getOpeningHoursStart());
        record.getOpeningHours().setOpeningHoursEnd(shopBO.getOpeningHours().getOpeningHoursEnd());
        record.setBusinessArea(shopBO.getBusinessArea());
        record.setComment(shopBO.getComment());
        record.setEnabled(shopBO.getEnabled().getBooleanValue());
        return record;
    }

}


